import os

# from qiniu import Auth, put_data

# access_key = "cOHVAF0aKxB8dAwdkxABxlFSCpiW0bhRQaw0lsQf"
# secret_key = "VvPBoqE_pH6RNdQvEZCAoOx2oVtgsinxVY9TwfZq"
# q = Auth(access_key,secret_key)
import time

from qiniu import Auth, put_data

QINIU_DOMAIN = "http://qhq9d7bnb.hn-bkt.clouddn.com"


#

def upload_qiniu(filestorage, image_filename):
    access_key = "cOHVAF0aKxB8dAwdkxABxlFSCpiW0bhRQaw0lsQf"
    secret_key = "VvPBoqE_pH6RNdQvEZCAoOx2oVtgsinxVY9TwfZq"

    # 构建鉴权对象
    q = Auth(access_key, secret_key)

    # 要上传的空间
    bucket_name = "meiduo-django"

    # 设置 上传之后保存文件的名字
    filename = 'weitezh_' + image_filename

    # 生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, filename, 3600)

    # put_file()
    ret, info = put_data(token, filename, filestorage.read())

    if info.status_code == 200:
        url = QINIU_DOMAIN + '/' + filename

        return url
    return None


if __name__ == '__main__':
    path = "../data"
    dir_path = str(os.path.abspath(path))

    for i in os.listdir(path)[1:-2]:

        if os.path.isdir(dir_path+'\\'+i):
            print("文件夹")
            for f in os.listdir(dir_path+"\\"+i):
                if os.path.isdir(dir_path+'\\'+i+'\\'+f):
                    print("文件夹"+f)
                    for x in os.listdir(dir_path+'\\'+i+'\\'+f):
                        print("x=",x)
                        if os.path.isdir(dir_path+'\\'+i+'\\'+f+'\\'+x):
                            print("文件夹"+f+'\\'+x)

                        else:
                            print("文件",dir_path+'\\'+i+'\\'+f+'\\'+x)
                            print(dir_path)
                            time.sleep(1)

                else:
                    print(f)
